package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkRewardApportionCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkRewardApportionResultVo;
import com.ruoyi.logistic.domain.vo.NetworkRewardApportionVo;
import com.ruoyi.logistic.service.NetworkRewardApportionCollectService;
import com.ruoyi.logistic.service.NetworkRewardApportionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.scene.control.Tab;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RequestMapping("/network/rewardApportion")
@RestController
@Api(tags = "网点财务_奖罚分摊结算")
public class NetworkRewardApportionController {
    @Autowired
    private NetworkRewardApportionService networkRewardApportionService;
    @Autowired
    private NetworkRewardApportionCollectService networkRewardApportionCollectService;
    @Autowired
    private TableService tableService;

    @ApiOperation("显示奖罚分摊结算明细")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate) {
        List<NetworkRewardApportion> networkRewardApportionList = networkRewardApportionService.selectAll(pageDate);
        if (networkRewardApportionList == null || networkRewardApportionList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkRewardApportionList));
        }
    }

    @ApiOperation("添加奖罚分摊结算")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkRewardApportion networkRewardApportion) {
        Boolean isAdd = networkRewardApportionService.insert(networkRewardApportion);
        if (isAdd) {
            return R.ok("添加成功");
        } else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改奖罚分摊结算")
    @PostMapping("/update")
    public R update(@RequestBody NetworkRewardApportion networkRewardApportion) {
        Boolean isUpdate = networkRewardApportionService.update(networkRewardApportion);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("搜索奖罚分摊结算")
    @PostMapping("/search")
    public R search(@RequestBody NetworkRewardApportionVo networkRewardApportionVo) {
        List<NetworkRewardApportion> networkRewardApportionList = networkRewardApportionService.search(networkRewardApportionVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkRewardApportion());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(networkRewardApportionList));
        jsonObject.put("fields", fieldList);
        if (networkRewardApportionList == null || networkRewardApportionList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
    @ApiOperation("搜索结果汇总")
    @PostMapping("/total")
    @ResponseBody
    public R total(NetworkRewardApportionVo networkRewardApportionVo){
        NetworkRewardApportionStatistics statistics = networkRewardApportionService.total(networkRewardApportionVo);
        return R.ok(statistics);
    }
    @ApiOperation("明细汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody NetworkRewardApportionCollectVo networkRewardApportionCollectVo){
        List<NetworkRewardApportionCollect> collectList = networkRewardApportionCollectService.collect(networkRewardApportionCollectVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkRewardApportionCollect());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(collectList));
        jsonObject.put("fields", fieldList);
        if (collectList == null || collectList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
